$(function(){

	$('#btn').click(function(){
      if ($('#passwordForm').valid()) {

        var one=$('#btn1').val();
        var two=$('#btn2').val();
        var password=$.md5($('#password').val());
        var data={
          password : password,
        };

        var data1={
          password : $.md5($('#btn1').val())
        }

        //alert(JSON.stringify(data));

          if(one==two && one!=''){
        	 	$.ajax({
            	url:'/comparePassword',
            	type : 'POST',
            	data : data,
            	success : function(result){
                if(result==null || result==""){
                  alert('原密码错误');
                }
                else{
                  $.ajax({
                    url: '/modifyPassword',
                    type: 'POST',
                    data: data1,
                      success : function(result){
                       alert('修改成功');
                       location.href = '/modifyPassword';
                      },
                      error : function(result){
                       block.showMsg('修改出错误');
                      },
                  });
                }
              },
              error : function(result){
            	 	alert('error!');
            	},
            });
          }
          /*else if(one=='' || two=='' || password=='')
            alert('不能为空');

          else{
            alert('两次密码不一致');
          }*/
      }
  });

	$(window).load(function(){
	});

  $('#passwordForm').validate({
      rules: {
          password: {
              required: true,
          },
          btn1: {
              required: true,
          },
          btn2: {
              required: true,
              equalTo: "#btn1"
          },
      },
      messages: {
          password: {
              required:'必填',
          },
          btn1:{
              required:'必填',
          },
          btn2:{
              required:'必填',
              equalTo:'与新密码不一致'
          },
      }
  });

});